<form  method="post" action="search_article.php?go"  id="searchform">  
<input  type="text" name="name">  
<input  type="submit" name="submit" value="Zoek">  
</form>
<a href="javascript:ddtreemenu.flatten('treemenu1', 'contact')">Inklappen</a>
<?php

include('config.php');
$tbl_name = "categories";
$FileName = pathinfo($_SERVER['PHP_SELF'], PATHINFO_FILENAME); //dit geeft de naam van de pagina terug, zonder .php erachter.


$sql = mysql_query("select * FROM $tbl_name") or die(mysql_error());

//echo "<table border='3' width='550px;'><tr><td>subcat1</td><td>subcat2</td><td>subcat3</td></tr>";
$hoofdcat = " "; //telkens kijken we of de hoofdcategorie hetzelfde is of niet
$subcat = " "; //same shit, maar dan voor subcat
$lg=1;

echo"<ul id='treemenu1' class='treeview'>";
while($r = mysql_fetch_array($sql))

{

$subcat1 = $r['SubCategory1'];
$subcat2 = $r['SubCategory2'];
$subcat3= $r['SubCategory3']; 
if(!$subcat2 || $subcat2=='') { 
	if($lg==1){echo"</li>";}
	if($lg==3){echo"</ul></li></ul></li>";}
	if($lg==2){echo"</li></ul></li>";}
	echo "<li><a href='artikelen.php?cat1=$subcat1&act=cat'>$subcat1</a>";
	$lg=1; 
	

	}	
elseif(!$subcat3 || $subcat3=='') {
	if($subcat1 == $hoofdcat)
	{
		
		if($lg==1)echo"<ul>";
		if($lg==2){echo"</li>";	}
		if($lg==3){echo"</ul></li>";}
		echo"<li><a href='artikelen.php?cat1=$subcat1&cat2=$subcat2&act=cat'>$subcat2</a>";
		$subcat=$subcat2;
		$lg=2;

		
	}
	else{
		if($lg==1){echo"</li>";}
		if($lg==2){echo"</li></ul></li>";}
		if($lg==3){echo"</ul></li></ul></li>";}
		echo"<li><a href='artikelen.php?cat1=$subcat1&act=cat'>$subcat1</a>";echo" <ul><li><a href='artikelen.php?cat1=$subcat1&cat2=$subcat2&act=cat'>$subcat2</a>";
		$hoofdcat = $subcat1;
		$lg=2;

	}
}
else
{
	if($subcat1 == $hoofdcat)
	{
		if($subcat2 == $subcat)
		{
			if($lg==2){echo"<ul>";}//??????
			echo"<li><a href='artikelen.php?cat1=$subcat1&cat2=$subcat2&cat3=$subcat3&act=cat'>$subcat3</a></li>";
			$lg=3;
		}
		else{
		if($lg==1)echo"<ul>";
		if($lg==2){echo"</li>";	}
		if($lg==3){echo"</ul></li>";}
		echo"<li><a href='artikelen.php?cat1=$subcat1&cat2=$subcat2&act=cat'>$subcat2</a>";echo" <ul><li> <a href='artikelen.php?cat1=$subcat1&cat2=$subcat2&cat3=$subcat3&act=cat'>$subcat3</a></a></li>";
		$subcat = $subcat2;
		$lg=3;


		
		}
		
	}
	else{
		if($lg==1){echo"</li>";}
		if($lg==2){echo"</li></ul></li>";}
		if($lg==3){echo"</ul></li></ul></li>";}
		echo"<li><a href='artikelen.php?cat1=$subcat1&act=cat'>$subcat1</a><ul><li> <a href='artikelen.php?cat1=$subcat1&cat2=$subcat2&act=cat'>$subcat2</a>";echo"<ul><li> <a href='artikelen.php?cat1=$subcat1&cat2=$subcat2&cat3=$subcat3&act=cat'>$subcat3</a></li>";
		$hoofdcat = $subcat1;
		$subcat = $subcat2;
		$lg=3;
		
	}
}

}

//close up the table
echo "</ul></li></ul></li>";

?>
<script type="text/javascript">

//ddtreemenu.createTree(treeid, enablepersist, opt_persist_in_days (default is 1))

ddtreemenu.createTree("treemenu1", true)

</script>